<template>
  <div>
    <!-- 订货单审核-->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110" @resetChange="resetChange" :isSubmitBtn="isShowBtn"></TopFilter>
    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        columnsRef="wkcOEMWaybillQueryC"
        :isSelectColumn="false"
        :onColumnsChange="(columns) => (this.columns = columns)"
      >
        <template slot="controls">
          <multiuse-button size="small" type="primary" @click="addHandle(1)">导 出</multiuse-button>
        </template>
      </FilterTable>
    </Spin>

    <Drawer :visible.sync="detailVisible" :title="'货运单信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" width="72%">
      <detailModel :rowData="formData" @close="emitcloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { getList, exportDlr } from '@/api/dealerSale/OrderManagement/WaybillQueryC';
import detailModel from './detailModel';
import { exportExcelFile } from '@/utils';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'wkcOEMWaybillQueryC',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        isDealer: 10041001,
      },
      fetchApi: getList,
      formData: {},
      exportLoading: false,
      issearch: false,
      detailVisible: false,
      isAccountProject: false,
      ProjectId: '',
      activeName: 'first',
      selectList: [],
      isShowBtn: true,
    };
  },
  components: {
    detailModel,
  },
  mixins: [dictionary],
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    async addHandle(type) {
      if (type == 1) {
        // this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        //   confirmButtonText: '下载',
        //   cancelButtonText: '取消',
        //   type: 'warning',
        // })
        //   .then(() => {
        //     let json = this.fetchParams;
        //     this.exportLoading = true;
        //     exportDlr(json)
        //       .then((response) => {
        //         exportExcelFile(response.data, '货运单查询');
        //         this.exportLoading = false;
        //       })
        //       .catch((err) => {
        //         console.log(err);
        //       });
        //   })
        //   .catch(() => {
        //     this.$message({
        //       type: 'info',
        //       message: '已取消',
        //     });
        //   });
      }
    },
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async editHandle(data, type) {
      if (type === 2) {
        this.formData = data;
        this.detailVisible = true;
      }
    },
    emitcloseHandler() {
      this.detailVisible = false;
    },
    resetChange(val) {
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '货运单号',
          fieldName: 'transNo',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: 'SAP销售单号',
          fieldName: 'sapNo',
          placeholder: '请输入',
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 2)}>
                  详情
                </multiuse-button>
              </div>
            );
          },
        },
        {
          title: '区域',
          dataIndex: 'deptName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商代码',
          dataIndex: 'ownerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '货运单号',
          dataIndex: 'shipmentOrderNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: 'SAP销售单号',
          dataIndex: 'sapNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: 'DMS批售订单号 ',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '订单管理号',
          dataIndex: 'doNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '收车地址',
          dataIndex: 'address',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '联系人',
          dataIndex: 'linkMan',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '联系电话',
          dataIndex: 'linkPhone',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '承运单位',
          dataIndex: 'carrierCompany',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '承运人',
          dataIndex: 'carrierPerson',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '承运时间',
          dataIndex: 'carrierDate',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '发车人',
          dataIndex: 'departurePerson',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '承运司机',
          dataIndex: 'carrierDriver',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '司机联系方式',
          dataIndex: 'carrierDriverPhone',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '收车人',
          dataIndex: 'receiver',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '收车时间',
          dataIndex: 'receiveDate',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '运输方式',
          dataIndex: 'transportType',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.transportType, '2409')}</span>;
          },
        },
        {
          title: '物料编码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '物料描述',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '配置',
          dataIndex: 'configName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '选装',
          dataIndex: 'optionName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '内饰',
          dataIndex: 'trimName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '外饰',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ];
    },
  },
};
</script>